/*
 * TCSS 422 Web Spider Project
 * Group Money: Al McKenzie, Michael Pitts, Taylor Zielske
 */

package control;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * This class stores the user settings passed to the program by the user in the StartGUI.
 * It also stores the default settings that will be used if nothing is specified by
 * the user.
 * 
 * @author Michael Pitts
 * @author Taylor Zielske
 * @version Nov 8, 2011
 */
public final class UserSettings {
	
	/**
	 * The collection of seed urls that will be used to start the web crawl.
	 */
	private final Collection<String> my_seeds;
	
	/**
	 * Collection of banned urls, that should under no circumstances be searched.
	 */
	private final Collection<String> my_banned_links;
	
	/**
	 * Collection of serach terms to look for while crawling the web.
	 */
	private final Collection<String> my_search_terms;
	
	/**
	 * The streams that will be used to output data to.
	 */
	private final PrintStream[] my_print_streams;
	
	/**
	 * The number and distribution of threads while crawling.  If null, single thread
	 * model.
	 */
	private final int[] my_num_threads;
	
	/**
	 * The format the data output will take.
	 */
	private final boolean my_run_gui;
	
	/**
	 * The maximum number of sites to visit.
	 */
	private final int my_max_sites;
	/**
	 * How often the gui should update
	 */
	private final int my_update_frequency;
	
	/**
	 * Creates a new UserSetting.
	 * @param the_seeds are the urls to star the search on.
	 * @param the_banned_links are the urls to never search on.
	 * @param the_search_terms are the words to look for in the urls crawled.
	 * @param the_print_streams are the output streams to send data to.
	 * @param the_num_threads are the number and distribution of threads to run 
	 * the crawler.  May be left as null, indicating single thread only.
	 * @param the_run_gui is if the gui will display the results
	 * @param the_max_sites the max sites to visit
	 * @param the_update_frequency how often to update the gui.
	 */
	public UserSettings(final Collection<String> the_seeds, 
			final Collection<String> the_banned_links, 
			final Collection<String> the_search_terms,
			final PrintStream[] the_print_streams,
			final int[] the_num_threads, final boolean the_run_gui,
			final int the_max_sites, final int the_update_frequency) {
		my_seeds = new ArrayList<String>(the_seeds);
		my_banned_links = new ArrayList<String>(the_banned_links);
		my_search_terms = new ArrayList<String>(the_search_terms);
		my_print_streams = the_print_streams;
		my_num_threads = the_num_threads;
		my_run_gui = the_run_gui;
		my_max_sites = the_max_sites;
		my_update_frequency = the_update_frequency;
	}
	

	/**
	 * Gets the seed urls for the web crawler.
	 * @return the seed urls to search on.
	 */
	public Collection<String> getSeeds() {
		return Collections.unmodifiableCollection(my_seeds);
	}

	/**
	 * Gets the urls banned from being searched.
	 * @return the Collection of urls that should not be searched.
	 */
	public Collection<String> getBannedLinks() {
		return Collections.unmodifiableCollection(my_banned_links);
	}

	/**
	 * Gets the collection of terms to search on for each url crawled.
	 * @return the words to search for while crawling the web.
	 */
	public Collection<String> getSearchTerms() {
		return Collections.unmodifiableCollection(my_search_terms);
	}

	/**
	 * Gets the print streams (if any) that are to be used to send output to.  May
	 * return a null if no output is requested other than through the GUI.
	 * @return the print streams to send data to, or null if no data is to be output.
	 */
	public PrintStream[] getPrintStreams() {
		return my_print_streams;
	}
	
	/**
	 * Gets the number and distribution of the threads, or null if single threaded.
	 * @return the number and distribution of threads to be used, or null for single
	 * threaded.
	 */
	public int[] getNumberThreads() {
		return my_num_threads;
	}
	
	/**
	 * Gets the number of sites to visit for this program's search.
	 * @return the integer number of sites to visit.
	 */
	public int getMaxSites() {
		return my_max_sites;
	}
	
	/**
	 * Gets weather the program will keep updating the gui.
	 * @return true if the gui will be updated regularly, false otherwise.
	 */
	public boolean getDisplayGUI() {
		return my_run_gui;
	}
	/**
	 * Gets of often the program will keep updating the gui.
	 * @return how often to update the gui
	 */
	public int getUpdateFrequency() {
		return my_update_frequency;
	}
	
	/**
	 * Gets a default user setting.
	 * @return a new user settings with the default settings applied.
	 */
	public static final UserSettings getDefaultSettings() {
		Collection<String> seed = new ArrayList<String>();
		seed.add("http://faculty.washington.edu/gmobus/ ");
		//seed.add("http://www.google.com/");
		Collection<String> banned = new ArrayList<String>();
		banned.add("http://questioneverything.typepad.com/");
		Collection<String> searchterms = new ArrayList<String>();
		searchterms.add("intelligence");
		searchterms.add("artificial");
		searchterms.add("agent");
		searchterms.add("university");
		searchterms.add("research");
		searchterms.add("science");
		searchterms.add("robot");
		PrintStream[] p = null;
		int threads[] = null;
		UserSettings us = new UserSettings(seed, banned, searchterms, p, threads, true, 500, 10);
		return us;
	}
}
